
/*  Include file for ERIM Golf League programs  1999 */
#ifndef GOLF_H
#define GOLF_H

#define MAX_TEAMS   20          /* Max number of league teams */
#define MAX_PLAYERS 100         /* Max of all players, team members plus subs */
#define MAX_NAME_LENGTH 30      /* Used to define buffers for the players names */
#define MAX_FILENAME_LEN 100    /* used to dimension file name buffers   */
#define HCP_WINDOW_LEN   6      /* Only the last 6 scores are used to compute weekly
                                   handicaps  */
#define BEST_HCP_SCORES   3
#define MAX_RNDS  20            /* Can not process more than this many weekly matches */
#define NO_SCORE  -9            /* I assume no one will shot a 9 under score   */
#define NO_NET_SCORE  -8        /* the-8 is just so I can id the field when 
                                   viewing the master file  */
#define NO_HCP    -7            /* flag indicating a player does not have a hcp */
#define NO_PUTTS  -6            /* no putts turned in or did not play */
#define NO_PTS    -5            /* did not play a round */
#define NO_SUB    -4            /* init value for player record  */
#define NO_NINE   'x'           /* init value for player record  */
#define NO_HOLES_PLAYED  -3     // default value in master file for num of holes the player played for each rnd
#define FIRST_PLAYER 1          /* array index of the first player - we ignore the
                                   zero record of the player array   */
#define TOTAL_PAR  36           /* par for nine holes at Leslie--front and back */
#define FRONT  'f'
#define BACK   'b'
#define PAR_AS_SUB  0           // par subs when there is a forfiet
#define WIN         2           // per hole points for win, tie, lose
#define LOSE        0
#define TIE         1
#define MAX_INDIVIDUAL_PTS 18.0 // max number of match points a individual player can win
#define BIGNUM 999.0            // initial value in search for lowest score, also used in the
                               // routine "scoreMatch" when the 10x rule applies
#define TENX_FLAG  9            // when this value is in a player's putt record it means he
                              // picked up after 10 strokes  (10x rule)

#define NO_PLAYERS_PER_MATCH 4

#define true  1
#define false 0

typedef struct {
    int id_number;              /* each player has a number */
    char name[MAX_NAME_LENGTH + 1]; /* add a char to ensure room for a string 
                                       terminater   */
    char initial;
    float curr_hcp;             /* use this hcp to score the match */
    float ESCscore;             // stokes over par may be limited by player's hcp 
    int subNumber[MAX_RNDS];    /* who sub'd for a team member   */
    float ESCAdjustedScores[HCP_WINDOW_LEN];    /* use ths scores in this vector to
                                                   compute new hcps */
    char whichNinePlayed[MAX_RNDS]; /* front or back nine  */
    int numHolesPlayed[MAX_RNDS];   /* num of holes played for each round */
    int all_scores[MAX_RNDS];   /* remember all scores */
    int netScores[MAX_RNDS];    // remember the net scores  (score - the player's hcp at the time)
    int putts[MAX_RNDS];        /* remember all the putting totals */
    int matchPointsWon[MAX_RNDS];
} player_t;

typedef struct {
    int matchNumber;
    int month;
    int day;
    int year;
    int numMatchesPlayed;
} matchFileHeaderRecord_t;

typedef struct {
    int team1;
    int team2;
    char whichNine;
    int nholesPlayed;
} teamMatchHeader_t;

typedef struct {
    int id;
    int subFor;
    float hcp;
    int forfiet;
    int totalScore;
    int netScore;               // not used
    int totalPts;
    int pts[9];
    int scores[9];
    int hcpStrokes[9];
    int adjScores[9];
    int putts[9];
} individualMatch_t;

typedef struct {
    int holeRank[9];
    int holePar[9];
} course_t;

 // data structures used to generate the match results report

const char monthNames[12][10] =
    { "January", "February", "March", "April", "May", "June", "July",
    "August", "September", "October", "November", "December"
};

typedef struct {
    int teamNumber;
    int ptsWonThisMatch;
    int teamPts;
    int teamCaptain;
    int teamMate;
} teamsInfo_t;


// definitions: now for Eagle Crest Golf Course
const int frontPar[9]  = { 4, 4, 4, 3, 5, 3, 4, 4, 5 };
const int backPar[9]   = { 5, 4, 4, 4, 3, 4, 5, 3, 4 };
// hole number in order of increasing handicap (decreasing difficulty)
const int frontRank[9] = { 5, 9, 2, 1, 7, 3, 8, 4, 6 }; 
const int backRank[9]  = { 7, 1, 3, 4, 6, 2, 9, 8, 5 };

void readMasterFile(char *fileName, int &nt, int &np);

// globals
extern teamsInfo_t teamsInfo[MAX_TEAMS];
extern course_t courseSettings; // holds par and hole ranks for scoring the round
extern individualMatch_t matchPlayers[NO_PLAYERS_PER_MATCH];
extern teamMatchHeader_t teamMatchHeader;
extern matchFileHeaderRecord_t matchFileHeader;
extern player_t players[MAX_PLAYERS + 1];   /* use the players id's as index.  The
                                               zero element of this vector is ignored */
#endif
